#import <CoreFoundation/CoreFoundation.h> 

#import <IOKit/IOKitLib.h> 
#import <IOKit/serial/IOSerialKeys.h> 
#import <IOKit/IOBSD.h> 

#import <Foundation/Foundation.h>

#import "ModemUSB.h"

int main () 
{
	int         fileDescriptor; 
	kern_return_t   kernResult; 
	io_iterator_t   serialPortIterator; 
	char        deviceFilePath[MAXPATHLEN]; 
	
	kernResult = [ModemUSB findModems: &serialPortIterator];
	kernResult = [ModemUSB getModemPath:serialPortIterator devPath:deviceFilePath pathSize:sizeof(deviceFilePath)];
	IOObjectRelease(serialPortIterator);    // Release the iterator. 

	if (!deviceFilePath[0]) 
	{ 
		printf("No modem port found.\n"); 
		return EX_UNAVAILABLE; 
	} 
	
	// Open the modem port, initialize the modem, then close it. 
	ModemUSB* modem = [[ModemUSB alloc] init];
	
	fileDescriptor = [modem openSerialPort:deviceFilePath];
	if (fileDescriptor == kMyErrReturn) 
	{ 
		return EX_IOERR;
	} 
	
	if([modem initModem])
	{ 
		printf("Modem initialized successfully.\n");
		
		[modem sendSMS:"Teste 02 do Modem 3G" toNumber:"5199138279"];
	} 
	else 
	{ 
		printf("Could not initialize modem.\n"); 
	}
	
	[modem closeSerialPort];
	printf("Modem port closed.\n");
 	
	[modem dealloc];
	return EX_OK;
}
